package web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

import bus.PriceIncrease;
import bus.ProductManager;

public class PriceIncreaseFormController extends SimpleFormController
{
	private ProductManager productManager;

	public ModelAndView onSubmit( Object command )
	{
		int increase = ( (PriceIncrease) command ).getPercentage();
		productManager.increasePrice( increase );
		return new ModelAndView( new RedirectView( getSuccessView() ) );
	}
	
	protected Object formBackingObject( HttpServletRequest request )
	{
		PriceIncrease priceIncrease = new PriceIncrease();
		priceIncrease.setPercentage( 20 );
		return priceIncrease;
	}
	
	public ProductManager getProductManager() {
		return productManager;
	}

	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
	}
}
